/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import imageviewerdb.ImageDb;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Stroke;
import java.awt.geom.Rectangle2D;
import javax.swing.JPanel;

/**
 *
 * @author Daniel
 */
public class ImageThumbnail extends JPanel {
    private ImageDb image;
    private boolean square;
    private Image thumb;
    private int pos = 0; //la posicion que ocupa en el array

    public ImageThumbnail(ImageDb image) {
        this.image = image;
        thumb = image.getThumbnail();
        //System.out.println(thumb);
    }

    public void setPos(int pos) {
        this.pos = pos;
    }

    public int getPos() {
        return pos;
    }        
    
    public void drawSquare(boolean d)
    {
        square = d;  
    }
    
    public String getPath()
    {
        return image.getPath();
    }
    
    public ImageDb getImageDb()
    {
        return image;    
    }
                        
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.black);
        g2.drawImage(thumb, 0, 0, getWidth(), getHeight(), null);        
        g2.drawRect(0, 0, getWidth(), getHeight());
        if(square){
            g2.setColor(Color.red); 
            Rectangle2D r = new Rectangle2D.Double(0, 0, getWidth(), getHeight());
            Stroke pincel = new BasicStroke(5.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND);
            g2.setStroke(pincel);
            g2.draw(r);
        }                   
    }    

}
